package com.example.demo.rest.ecom;

import com.example.demo.api.ecom.LSessionApi;
import com.example.demo.bean.vo.LSessionUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@RestController
public class SessionController {

    @Autowired
    LSessionApi lSessionApi;

    @PutMapping("/session/create")
    public Object sessionInit() {
        Object sessionId = lSessionApi.sessionInit();
        LSessionUser lSessionUser = new LSessionUser();
        lSessionUser.setEmail("robin.mahacek@onepointone.com");
        lSessionUser.setLogin(true);
        lSessionUser.setId("1300196273338");
        lSessionUser.setType("LENOVOID");
        lSessionUser.setVerified(true);
        Map<String, Object> attributes = new HashMap<>();
        attributes.put("realm", "account.lenovo.com");
        lSessionUser.setAttributes(attributes);
        lSessionApi.putSessionUser(String.valueOf(sessionId), lSessionUser);
        return sessionId;
    }

    @GetMapping("/session/{sessionId}")
    public String getSessionUser(@PathVariable("sessionId") String sessionId) {
        return lSessionApi.getSessionUser(sessionId);
    }

    @DeleteMapping("/session/{sessionId}")
    public Object deleteSessionUser(@PathVariable("sessionId") String sessionId) {
        return lSessionApi.deleteSessionUser(sessionId);
    }

    @GetMapping("putGateKeeperKey")
    public Object putGateKeeperKey(@RequestParam("sessionId") String sessionId, @RequestParam("smbStore") String smbStore) {
        return lSessionApi.putGateKeeperKey(sessionId, smbStore);
    }


}
